package com.qk.management.controller;

import com.qk.common.Result;
import com.qk.entity.Role;
import com.qk.management.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*
 *  @author SHCJ
 *  @created 2025/10/6 13:21
 *  @description
 */
@RestController
@RequestMapping("/roles")
public class RoleController {
    @Autowired
    private RoleService roleService;
//    分页查询
    @GetMapping
    public Result page(String name, String label, Integer page, Integer pageSize){

        return Result.success(roleService.page(name,label,page,pageSize));
    }

//    删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        roleService.delete(id);
        return Result.success();
    }

//    新增
    @PostMapping
    public Result add(@RequestBody Role role){
        roleService.addRole(role);
        return Result.success();
    }

//    根据id查询
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
        return Result.success(roleService.findById(id));
    }

//    修改
    @PutMapping
    public Result update(@RequestBody Role role){
        roleService.update(role);
        return Result.success();
    }

//    查询所有角色
    @GetMapping("/list")
    public Result selectAll(){
        return Result.success(roleService.selectAll());
    }
}
